package com.zzx.test.reflection;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @ClassName: ReflectionMethodTest1
 * @Description: 反射常用方法
 * @Author zhouzhixin
 * @Date 2021/12/3
 * @Version 1.0
 */
public class ReflectionMethodTest1 {

    @Test
    public void test1() {
        try {
            Class<?> aClass = Class.forName("com.zzx.test.entity.Person");
            Method[] methods = aClass.getDeclaredMethods();
            for (Method method : methods) {
                method.setAccessible(true);
                System.out.println(method.getName());
            }
            System.out.println("-------------------");
            Field[] fields = aClass.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                System.out.println(field.getName());
            }
            System.out.println("-------------------");
            Constructor<?>[] constructors = aClass.getDeclaredConstructors();
            for (Constructor<?> constructor : constructors) {
                constructor.setAccessible(true);
                System.out.println(constructor.getParameterCount());
                System.out.println(constructor.getName());
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
